from pms.common.views import PostFormula
from user.models import User
from technology.models import Technology
from user.utils.technology import user_add_technology


class API(PostFormula):

    def handle(self, req):
        uid = req['uid']
        tid = req['tid']
        user = User.objects.get(id=uid)
        if user == self.user:  # 是当前用户
            self.assert_one_of_permissions([5, 6])
        else:
            self.assert_permissions([6])
        know = user_add_technology(user, Technology.objects.get(id=tid))
        return self.success_respond({
            'tid': know.tid_id
        })
